Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Panel Data - treatment*for group data based on within group characteristics

    Hello,

    I am interested in assigning a treatment to a firm if it was domestic (foreign=0) in year 2003 and foreign (foreign=1) in 2004. All firms for wich this criterion holds should be counted as treated (for alle years). However, a problem is the fact that this implies that each firm has to be evaluated on two consecutive rows. A further problem is that firms are not always available for all of this years. I am not having an idea how to approach.
    Further the dataset contained 35000 firms s.t. it is impossible to go through it by hand.

    Thank you very much in advance.






    Attached Files

  • #2
    Code:
    by firmid: egen byte domestic2003 = max(year == 2003 & foreign == 0)
    by firmid: egen byte foreign2004 = max(year == 2004 & foreign == 1)
    gen byte treated = domestic2003 & foreign2004
    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    Comment


    • #3
      Dear Clyde, thank you so much. The code works very well. And next time I will use dataex.
      All the best

      Comment

      Working...
      X